home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / PhraseInStr.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.2 KB  |  69 lines

  1. #include <exec/types.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. #include <clib/extras/string_protos.h>
  6.  
  7. /****** extras.lib/PhraseInStr ******************************************
  8. *
  9. *   NAME
  10. *       PhraseInStr -- Find a phrase or word in a string.
  11. *
  12. *   SYNOPSIS
  13. *       str = PhraseInStr(InStr, Phrase)
  14. *
  15. *       STRPTR PhraseInStr(STRPTR , Phrase)
  16. *
  17. *   FUNCTION
  18. *       Locates a phrase or word in a string.
  19. *
  20. *   INPUTS
  21. *       InStr - String to search in.
  22. *       Phrase to search for.
  23. *
  24. *   RESULT
  25. *       returns pointer to phrase in InStr or NULL.
  26. *
  27. *   EXAMPLE
  28. *
  29. *   NOTES
  30. *       case insensitive.
  31. *
  32. *   BUGS
  33. *
  34. *   SEE ALSO
  35. *
  36. ******************************************************************************
  37. *
  38. */
  39.  
  40. STRPTR PhraseInStr(STRPTR InStr,STRPTR Phrase)
  41. {
  42.   LONG l,l2,t=0;
  43.   
  44.   if(InStr && Phrase)
  45.   {
  46.     l2=strlen(Phrase);
  47.     l=strlen(InStr)-l2;
  48.     
  49.     while(!isalnum(InStr[t]))
  50.       t++;
  51.     
  52.     while(t<=l)
  53.     {
  54.       if(strnicmp(&InStr[t],Phrase,l2)==0)
  55.       {
  56.         if(!isalnum(InStr[t+l2]))
  57.           return(&InStr[t]);
  58.       }
  59.       t++;
  60.       while(isalnum(InStr[t]))
  61.         t++;
  62.       while(!isalnum(InStr[t]))
  63.         t++;
  64.     }
  65.   }
  66.   return(0);
  67. }
  68.  
  69.